package com.ymttest.database.sqlwapper;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtCouponSetting;
import com.ymttest.utils.EnvSetup;

public class YmtCouponSettingWapper {
    SqlManager manage;

    public YmtCouponSettingWapper() {
        manage = new SqlManager("ymt" + EnvSetup.getEnv());
    }

    //
    // /**
    // * 插入优惠券规则
    // *
    // * @param MaxUseTimePerUser
    // * 每个用户最大领用次数
    // * @param ScenarioId
    // * 优惠券场景
    // */
    // public void insertYmtCouponSetting(int MaxUseTimePerUser, int ScenarioId) {
    // YmtCouponSetting data = new YmtCouponSetting();
    // data.setBismobileverify(false);
    // // 结束时间
    // String dvalidend = DateUtils.getBeforeOrNextDay(30);
    // data.setDvalidend(dvalidend);
    // // 开始时间
    // String Dvalidstart = DateUtils.getBeforeOrNextDay(0);
    // data.setDvalidstart(Dvalidstart);
    // data.setIcouponusecount(0);
    // // 1-现金 2-返红包 3-不使用
    // data.setIcouponusetype(1);
    // // 最大使用次数
    // data.setImaxusetime(2);
    // // 每个用户最大领取数量
    // data.setImaxusetimeperuser(MaxUseTimePerUser);
    // data.setIscenarioid(ScenarioId);
    // data.setIusetotalcount(500);
    // data.setSapplymemo("测试测试");
    // data.setSapplyuser("test");
    // int i = manage.insert("com.ymttest.database.mapping.YmtCouponSettingMapper.insertSelective",
    // data);
    // manage.commit();
    // }
    //
    // /**
    // * 查询最后一条优惠券规则Id
    // *
    // * @return
    // */
    // @SuppressWarnings("unchecked")
    // public Integer getLastYmtCouponSettingId() {
    // ArrayList<YmtCouponSetting> list = new ArrayList<YmtCouponSetting>();
    // YmtCouponSettingExample data = new YmtCouponSettingExample();
    // data.setDistinct(false);
    // data.setOrderByClause("iCouponSettingId desc");
    // list = (ArrayList<YmtCouponSetting>) manage.getSelectResults(
    // "com.ymttest.database.mapping.YmtCouponSettingMapper.selectByExample", data);
    // return list.get(0).getIcouponsettingid();
    // }
    //

    public List<YmtCouponSetting> selectBySApplyMemo(String sApplyMemo) {
        List<YmtCouponSetting> result = manage
                .getSelectResults(
                        "com.ymttest.database.mapping.YmtCouponSettingMapper.selectBySApplyMemo",
                        sApplyMemo);
        return result;
    }

    public List<YmtCouponSetting> selectByiCouponSettingId(int iCouponSettingId) {
        List<YmtCouponSetting> result = manage
                .getSelectResults(
                        "com.ymttest.database.mapping.YmtCouponSettingMapper.selectByiCouponSettingId",
                        iCouponSettingId);
        manage.commit();
        return result;
    }

    public void setbIsMobileVerifyTrue(int iCouponSettingId) {
        manage
                .update(
                        "com.ymttest.database.mapping.YmtCouponSettingMapper.setbIsMobileVerifyTrue",
                        iCouponSettingId);
        manage.commit();
    }

    public void setdValidStart(int iCouponSettingId, Date dValidStart) {
        Map m = new HashMap();
        m.put("iCouponSettingId", iCouponSettingId);
        m.put("dValidStart", dValidStart);
        manage
                .update(
                        "com.ymttest.database.mapping.YmtCouponSettingMapper.setdValidStart",
                        m);
        manage.commit();
    }

    public void setdValidEnd(int iCouponSettingId, Date dValidEnd) {
        Map m = new HashMap();
        m.put("iCouponSettingId", iCouponSettingId);
        m.put("dValidEnd", dValidEnd);
        manage
                .update(
                        "com.ymttest.database.mapping.YmtCouponSettingMapper.setdValidEnd",
                        m);
        manage.commit();
    }

    public void setiReceiveCount(int iCouponSettingId, int iReceiveCount) {
        Map m = new HashMap();
        m.put("iCouponSettingId", iCouponSettingId);
        m.put("iReceiveCount", iReceiveCount);
        manage
                .update(
                        "com.ymttest.database.mapping.YmtCouponSettingMapper.setiReceiveCount",
                        m);
        manage.commit();
    }

    public void setiEffectiveType(int iCouponSettingId, int iEffectiveType) {
        Map m = new HashMap();
        m.put("iCouponSettingId", iCouponSettingId);
        m.put("iEffectiveType", iEffectiveType);
        manage
                .update(
                        "com.ymttest.database.mapping.YmtCouponSettingMapper.setiEffectiveType",
                        m);
        manage.commit();
    }

    public void setiMaxUseTime(int iCouponSettingId, int iMaxUseTime) {
        Map m = new HashMap();
        m.put("iCouponSettingId", iCouponSettingId);
        m.put("iMaxUseTime", iMaxUseTime);
        manage
                .update(
                        "com.ymttest.database.mapping.YmtCouponSettingMapper.setiMaxUseTime",
                        m);
        manage.commit();
    }

    public static void main(String[] args) {
        YmtCouponSettingWapper test = new YmtCouponSettingWapper();
        // test.insertYmtCouponSetting(3,11);
        // Logger.debug(test.getLastYmtCouponSettingId());
    }
}
